package com.thinkgem.jeesite.modules.patents.web;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.patents.entity.Patents;
import com.thinkgem.jeesite.modules.patents.service.PatentsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "${adminPath}/patents/anythingtest")
public class AnythingView extends BaseController {
    @Autowired
    private PatentsService patentsService;


    /**
     * 年度趋势分析
     **/
    @RequiresPermissions("patents:patents:view")
    @RequestMapping(value = "patenttop")
    public String connector(Patents patents, HttpServletRequest request, HttpServletResponse response, Model model) {
        List<Map<String, Object>> mapList = Lists.newArrayList();
        Map<String, Object> topOnlyMap = Maps.newHashMap();
        List<Patents> topList = patentsService.getTopList(patents);
        patents.setUserType("大专院校");
        List<Patents> topSchoolList = patentsService.getTopList(patents);
        for(int i=0;i<topList.size();i++){
            int s = i+1;
            String UserName = topList.get(i).getPatentUser();
            String count = topList.get(i).getCount();
            topOnlyMap.put("Name"+s,UserName);
            topOnlyMap.put("Count"+s,count);

            String schoolUserName = topSchoolList.get(i).getPatentUser();
            String schoolCount = topSchoolList.get(i).getCount();
            topOnlyMap.put("schoolName"+s,schoolUserName);
            topOnlyMap.put("schoolCount"+s,schoolCount);
        }

        if(topList.size()<10){
            for (int j=1;j<=10-topList.size();j++){
                int z = j+topList.size();
                String UserName = " ";
                String count = "0";
                topOnlyMap.put("Name"+z,UserName);
                topOnlyMap.put("Count"+z,count);

                topOnlyMap.put("schoolName"+z,UserName);
                topOnlyMap.put("schoolCount"+z,count);
            }
        }
        mapList.add(topOnlyMap);
        model.addAttribute("mapList", mapList);
        return "modules/patents/patentTop";
    }
}
